/**
 * 注射器
 */
Injector = Widget.extend({
	ctor:function(parent){
		this._super();
		parent.addChild(this,20);
		this.setTag(TAG_INJECTOR);
		this.init();
	},
	init : function(){
		this.setVisible(false);
		
		//注射器1（针头）--body--上面的注射器
		this.body1 = new Button(this, 10, TAG_COLD_INJECTOR1, "#run/injector1.png",this.callback);
		this.body1.setPosition(cc.p(620,450));
		this.body1.setRotation(90);
		//注射器2（外壳）
		var injector2 = new Button(this.body1, 15, TAG_COLD_INJECTOR2, "#run/injector2.png",this.callback);
		injector2.setPosition(cc.p(46,136));
		//注射器3（推）
		var injector3 = new Button(this.body1, 11, TAG_COLD_INJECTOR3, "#run/injector3.png",this.callback,this);
		injector3.setPosition(cc.p(44,234));
		//红色1
		var red1 = new cc.Sprite("#run/red1.png");
		this.body1.addChild(red1,8,TAG_COLD_RED1);
		red1.setPosition(cc.p(44,128));
		red1.setAnchorPoint(0.5, 0);
		red1.setScale(1, 3);
		//红色2
		var red2 = new cc.Sprite("#run/red2.png");
		this.body1.addChild(red2,7);
		red2.setPosition(cc.p(43,127));
		this.body1.setCascadeOpacityEnabled(true);
		
		//注射器1（针头）--body--下面的注射器
		this.body2 = new Button(this, 10, TAG_HOT_INJECTOR1, "#run/injector1.png",this.callback);
		this.body2.setPosition(cc.p(620,380));
		this.body2.setRotation(90);
		//注射器2（外壳）
		var injector2 = new Button(this.body2, 15, TAG_HOT_INJECTOR2, "#run/injector2.png",this.callback);
		injector2.setPosition(cc.p(46,136));
		//注射器3（推）
		var injector3 = new Button(this.body2, 11, TAG_HOT_INJECTOR3, "#run/injector3.png",this.callback,this);
		injector3.setPosition(cc.p(44,234));
		//红色1
		var red1 = new cc.Sprite("#run/red1.png");
		this.body2.addChild(red1,8,TAG_HOT_RED1);
		red1.setPosition(cc.p(44,128));
		red1.setAnchorPoint(0.5, 0);
		red1.setScale(1, 3);
		//红色2
		var red2 = new cc.Sprite("#run/red2.png");
		this.body2.addChild(red2,7);
		red2.setPosition(cc.p(43,127));
		this.body2.setCascadeOpacityEnabled(true);
	},	
	callback:function(p){
		var action = gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_COLD_INJECTOR1:
			var cold_water = this.getParent().getChildByTag(TAG_COLD_BODY);
			var hot_water = this.getParent().getChildByTag(TAG_HOT_BODY);
			var rotate = cc.rotateTo(2, 12);
			var move = cc.moveTo(2,cc.p(510,267));
			var spawn = cc.spawn(rotate, move);
			//注射结束，冷水移出
			var body1_moveby = cc.moveBy(1, cc.p(0,180));
			var sequence = cc.sequence(cc.callFunc(function() {
				var rot1 = cc.rotateTo(1, 45);
				var mov1 = cc.moveTo(1, cc.p(850,425));
				var spw1 = cc.spawn(rot1, mov1);
				var rot2 = cc.rotateTo(1, 12);
				var mov2 = cc.moveTo(1, cc.p(830,267));
				var spw2 = cc.spawn(rot2, mov2);
				var seq = cc.sequence(spw1,spw2);
				this.body2.runAction(seq);
			}, this),spawn,cc.delayTime(0.5),cc.callFunc(function() {
				//红墨水
				var cold_red = new cc.Sprite("#run/moshui.png");
				cold_water.addChild(cold_red);
				cold_red.setScale(0.2);
				cold_red.setPosition(cc.p(126,68));
				cold_red.runAction(cc.sequence(cc.spawn(cc.scaleTo(15, 2.1, 1.9),cc.moveTo(15,cc.p(162,168))),cc.callFunc(function() {
					gg.flow.next();
				}, this)));
				var hot_red = new cc.Sprite("#run/moshui.png");
				hot_water.addChild(hot_red);
				hot_red.setScale(0.2);
				hot_red.setPosition(cc.p(126,68));
				hot_red.runAction(cc.sequence(cc.spawn(cc.scaleTo(5, 2.1, 1.9),cc.moveTo(5,cc.p(162,168))),cc.callFunc(function() {
					var show = new ShowTip("热水中的红墨水比在冷水中扩散的快",cc.p(450,400));
				}, this)));
			}, this),cc.delayTime(0.5),cc.callFunc(function() {
				//注射结束，热水移出
				var body2_moveby = cc.moveBy(1, cc.p(0,180));
				this.body2.runAction(cc.sequence(body2_moveby,cc.fadeOut(0)));
			}, this),body1_moveby,cc.fadeOut(0));
			p.runAction(sequence);
			break;
		default:
			break;
		}
	}
});
